package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SoilPhysics;
import com.ruoyi.system.service.ISoilPhysicsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物理性质Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@Controller
@RequestMapping("/system/physics")
public class SoilPhysicsController extends BaseController
{
    private String prefix = "system/physics";

    @Autowired
    private ISoilPhysicsService soilPhysicsService;

    @RequiresPermissions("system:physics:view")
    @GetMapping()
    public String physics()
    {
        return prefix + "/physics";
    }

    /**
     * 查询物理性质列表
     */
    @RequiresPermissions("system:physics:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SoilPhysics soilPhysics)
    {
        startPage();
        List<SoilPhysics> list = soilPhysicsService.selectSoilPhysicsList(soilPhysics);
        return getDataTable(list);
    }

    /**
     * 导出物理性质列表
     */
    @RequiresPermissions("system:physics:export")
    @Log(title = "物理性质", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SoilPhysics soilPhysics)
    {
        List<SoilPhysics> list = soilPhysicsService.selectSoilPhysicsList(soilPhysics);
        ExcelUtil<SoilPhysics> util = new ExcelUtil<SoilPhysics>(SoilPhysics.class);
        return util.exportExcel(list, "物理性质数据");
    }

    /**
     * 新增物理性质
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物理性质
     */
    @RequiresPermissions("system:physics:add")
    @Log(title = "物理性质", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SoilPhysics soilPhysics)
    {
        return toAjax(soilPhysicsService.insertSoilPhysics(soilPhysics));
    }

    /**
     * 修改物理性质
     */
    @RequiresPermissions("system:physics:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SoilPhysics soilPhysics = soilPhysicsService.selectSoilPhysicsById(id);
        mmap.put("soilPhysics", soilPhysics);
        return prefix + "/edit";
    }

    /**
     * 修改保存物理性质
     */
    @RequiresPermissions("system:physics:edit")
    @Log(title = "物理性质", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SoilPhysics soilPhysics)
    {
        return toAjax(soilPhysicsService.updateSoilPhysics(soilPhysics));
    }

    /**
     * 删除物理性质
     */
    @RequiresPermissions("system:physics:remove")
    @Log(title = "物理性质", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(soilPhysicsService.deleteSoilPhysicsByIds(ids));
    }
}
